package com.imooc.utils;

import org.apache.commons.codec.digest.DigestUtils;

public class MD5Util {
	
	/**
	 * MD5包装
	 * @param src
	 * @return
	 */
	public static String md5(String src){
		return DigestUtils.md5Hex(src);
	}
	
	private static final String salt = "12345678";
	
	/**
	 * 前端传过来的密码加盐
	 * @param inputPass
	 * @return
	 */
	public static String inputPassFormPass(String inputPass){
		String str = "" +salt.charAt(0) + salt.charAt(2) + inputPass
				+ salt.charAt(5) + salt.charAt(4);
		return md5(str);
	}
	
	/**
	 * 再次md5，pass,salt入库
	 * @param args
	 */
	public static String formPassToDBPass(String formPass, String salt){
		String str = "" +salt.charAt(0) + salt.charAt(2) + formPass
				+ salt.charAt(5) + salt.charAt(4);
		return md5(str);
	}
	
	public static String inputPassToDBPass(String inputPass, String salt){
		String formPass = inputPassFormPass(inputPass); // 第一次md5
		String dbPass = formPassToDBPass(formPass, salt); // 第二次md5
		return dbPass;
	}
	
	
	public static void main(String[] args) {
		
		 /**
		  * str=1312345665
			d3b8d9e2e41c8c52100e44799e8862a0
			255ed9695c8c5a9bd4774a32abf9c4cf
			255ed9695c8c5a9bd4774a32abf9c4cf

		  */
//	System.out.println("---->"+inputPassFormPass("123456"));
		
	//System.out.println(formPassToDBPass("d3b8d9e2e41c8c52100e44799e8862a0","12345678"));
	System.out.println(inputPassToDBPass("123456", "12345678"));
	}
	
}


